{% extends "base.html" %}

{% block title %}个人仪表板 - SteHub{% endblock %}

{% block content %}
<div class="row">
    <div class="col-12">
        <h2 class="mb-4"><i class="fas fa-tachometer-alt me-2"></i>个人仪表板</h2>
    </div>
</div>

<div class="row">
    <!-- 统计卡片 -->
    <div class="col-xl-3 col-md-6 mb-4">
        <div class="card border-left-primary shadow h-100 py-2">
            <div class="card-body">
                <div class="row no-gutters align-items-center">
                    <div class="col mr-2">
                        <div class="text-xs font-weight-bold text-primary text-uppercase mb-1">
                            发布的帖子
                        </div>
                        <div class="h5 mb-0 font-weight-bold text-gray-800">
                            {{ user_stats.posts_count }}
                        </div>
                    </div>
                    <div class="col-auto">
                        <i class="fas fa-comments fa-2x text-gray-300"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="col-xl-3 col-md-6 mb-4">
        <div class="card border-left-success shadow h-100 py-2">
            <div class="card-body">
                <div class="row no-gutters align-items-center">
                    <div class="col mr-2">
                        <div class="text-xs font-weight-bold text-success text-uppercase mb-1">
                            发表的评论
                        </div>
                        <div class="h5 mb-0 font-weight-bold text-gray-800">
                            {{ user_stats.comments_count }}
                        </div>
                    </div>
                    <div class="col-auto">
                        <i class="fas fa-comment fa-2x text-gray-300"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="col-xl-3 col-md-6 mb-4">
        <div class="card border-left-info shadow h-100 py-2">
            <div class="card-body">
                <div class="row no-gutters align-items-center">
                    <div class="col mr-2">
                        <div class="text-xs font-weight-bold text-info text-uppercase mb-1">
                            收到的点赞
                        </div>
                        <div class="h5 mb-0 font-weight-bold text-gray-800">
                            {{ user_stats.likes_received }}
                        </div>
                    </div>
                    <div class="col-auto">
                        <i class="fas fa-heart fa-2x text-gray-300"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="col-xl-3 col-md-6 mb-4">
        <div class="card border-left-warning shadow h-100 py-2">
            <div class="card-body">
                <div class="row no-gutters align-items-center">
                    <div class="col mr-2">
                        <div class="text-xs font-weight-bold text-warning text-uppercase mb-1">
                            在线状态
                        </div>
                        <div class="h5 mb-0 font-weight-bold text-gray-800">
                            {% if current_user.is_online %}
                            <span class="text-success">在线</span>
                            {% else %}
                            <span class="text-muted">离线</span>
                            {% endif %}
                        </div>
                    </div>
                    <div class="col-auto">
                        <i class="fas fa-user fa-2x text-gray-300"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="row">
    <!-- 最新帖子 -->
    <div class="col-lg-6 mb-4">
        <div class="card shadow">
            <div class="card-header py-3 d-flex justify-content-between align-items-center">
                <h6 class="m-0 font-weight-bold text-primary">我的最新帖子</h6>
                <a href="{{ url_for('forum.create_post') }}" class="btn btn-sm btn-primary">发布新帖</a>
            </div>
            <div class="card-body">
                {% if user_posts %}
                    <div class="list-group list-group-flush">
                        {% for post in user_posts %}
                        <a href="{{ url_for('forum.view_post', post_id=post.id) }}" 
                           class="list-group-item list-group-item-action">
                            <div class="d-flex w-100 justify-content-between">
                                <h6 class="mb-1">{{ post.title }}</h6>
                                <small>{{ post.created_at|relative_time }}</small>
                            </div>
                            <p class="mb-1 text-muted small">
                                {{ post.content|striptags|truncate(100) }}
                            </p>
                            <div class="small text-muted">
                                <i class="fas fa-eye me-1"></i>{{ post.view_count }}
                                <i class="fas fa-heart ms-2 me-1"></i>{{ post.like_count }}
                                <i class="fas fa-comment ms-2 me-1"></i>{{ post.comment_count }}
                            </div>
                        </a>
                        {% endfor %}
                    </div>
                {% else %}
                    <div class="text-center py-4">
                        <i class="fas fa-edit fa-2x text-muted mb-3"></i>
                        <p class="text-muted">还没有发布过帖子</p>
                        <a href="{{ url_for('forum.create_post') }}" class="btn btn-primary">
                            <i class="fas fa-plus me-2"></i>发布第一个帖子
                        </a>
                    </div>
                {% endif %}
            </div>
        </div>
    </div>

    <!-- 最新评论 -->
    <div class="col-lg-6 mb-4">
        <div class="card shadow">
            <div class="card-header py-3 d-flex justify-content-between align-items-center">
                <h6 class="m-0 font-weight-bold text-primary">我的最新评论</h6>
                <a href="{{ url_for('forum.posts') }}" class="btn btn-sm btn-primary">查看帖子</a>
            </div>
            <div class="card-body">
                {% if user_comments %}
                    <div class="list-group list-group-flush">
                        {% for comment in user_comments %}
                        <div class="list-group-item">
                            <div class="d-flex w-100 justify-content-between">
                                <h6 class="mb-1">
                                    <a href="{{ url_for('forum.view_post', post_id=comment.post.id) }}#comment-{{ comment.id }}">
                                        {{ comment.post.title|truncate(40) }}
                                    </a>
                                </h6>
                                <small>{{ comment.created_at|relative_time }}</small>
                            </div>
                            <p class="mb-1 text-muted small">
                                {{ comment.content|striptags|truncate(80) }}
                            </p>
                        </div>
                        {% endfor %}
                    </div>
                {% else %}
                    <div class="text-center py-4">
                        <i class="fas fa-comment fa-2x text-muted mb-3"></i>
                        <p class="text-muted">还没有发表过评论</p>
                        <a href="{{ url_for('forum.posts') }}" class="btn btn-primary">
                            <i class="fas fa-comments me-2"></i>去论坛看看
                        </a>
                    </div>
                {% endif %}
            </div>
        </div>
    </div>
</div>

<!-- 快速操作 -->
<div class="row">
    <div class="col-12">
        <div class="card shadow">
            <div class="card-header">
                <h6 class="m-0 font-weight-bold text-primary">快速操作</h6>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-3 text-center mb-3">
                        <a href="{{ url_for('forum.create_post') }}" class="btn btn-outline-primary w-100">
                            <i class="fas fa-edit fa-2x mb-2"></i><br>
                            发布帖子
                        </a>
                    </div>
                    <div class="col-md-3 text-center mb-3">
                        <a href="{{ url_for('chat.index') }}" class="btn btn-outline-success w-100">
                            <i class="fas fa-comment-dots fa-2x mb-2"></i><br>
                            进入聊天
                        </a>
                    </div>
                    <div class="col-md-3 text-center mb-3">
                        <a href="{{ url_for('auth.profile') }}" class="btn btn-outline-info w-100">
                            <i class="fas fa-user fa-2x mb-2"></i><br>
                            编辑资料
                        </a>
                    </div>
                    <div class="col-md-3 text-center mb-3">
                        <a href="{{ url_for('main.search') }}" class="btn btn-outline-warning w-100">
                            <i class="fas fa-search fa-2x mb-2"></i><br>
                            搜索内容
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}